//
//  YPRequestClient.m
//  Youpin
//
//  Created by xiaowuxiaowu on 2017/4/12.
//  Copyright © 2017年 xiaowuxiaowu. All rights reserved.
//

#import "TPRequestClient.h"
#import "UIButton+CountDown.h"
@implementation TPRequestClient
+(instancetype)sharedClient{
    
    static TPRequestClient *client;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        client = [[TPRequestClient alloc]init];
    });
    
    return client;
}

//微信登录
-(void)getWXLoginCode:(NSString *)code success:(successBlock)success
    failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{

    [self POST:@"login/oauth" parameters:@{@"code":xw_getNULLString(code),@"client_secret":@"tzn1Cmd70OX7k6Xb2qDkmmDIj33m7kCCklCwDkAS"} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//登录
-(void)getLoginName:(NSString *)name toPass:(NSString *)password code:(NSString *)code success:(successBlock)success
                      failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:name,@"mobile",password,@"password",code,@"code",code.length <=0?@"mobile":@"code" ,@"type",@"password",@"grant_type",@"2",@"client_id",@"tzn1Cmd70OX7k6Xb2qDkmmDIj33m7kCCklCwDkAS",@"client_secret",@"true",@"remember", nil];
    [self POST:@"login" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//注册
-(void)getLogin_get_phoneRegisterPhone:(NSString *)phone toPass:(NSString *)password toCode:(NSString *)code name:(NSString *)name success:(successBlock)success
                      failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:phone,@"mobile",password,@"password",name,@"nickname",code,@"code",@"password",@"grant_type",@"2",@"client_id",@"tzn1Cmd70OX7k6Xb2qDkmmDIj33m7kCCklCwDkAS",@"client_secret",@"true",@"remember", nil];
    
    [self POST:@"login/register" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}
/*| mobile |是  |string | 手机号 |
| code |是  |string | 验证码 |
| password | 是 |string | 密码 |
| grant_type | 是  | string | 获取令牌方式 ：password (固定的) |
| client_id | 是  | int | 客户端id(固定的)：2 |
| client_secret  | 是  | string | 证书秘钥(固定的)：tzn1Cmd70OX7k6Xb2qDkmmDIj33m7kCCklCwDkAS |
| remember  | 是  | boole | 是否记录登录状态(固定的)：true |
*/


//忘记密码
-(void)getLogin_forgetPswPhone:(NSString *)phone toPass:(NSString *)password toCode:(NSString *)code success:(successBlock)success
                               failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:phone,@"mobile",password,@"password",code,@"code", nil];
    [self POST:@"login/forget" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}
//login（登录）, register（注册） , bind（绑定手机）, edit（修改手机）, forget（找回密码）
NSString *NSStringFromLoginCodeStyle(LoginCodeStyle style){
    
    switch (style) {
        case LoginCodeStyleLogin:
            return @"login";
            break;
        case LoginCodeStyleSingn:
            return @"register";
            break;
        case LoginCodeStyleBindMobile:
            return @"bind";
            break;
        case LoginCodeStyleEditMobile:
            return @"edit";
            break;
        case LoginCodeStyleForget:
            return @"forget";
            break;
            
        default:
            break;
    }
}

//获取验证码  1：注册 2：找回密码 3：设置手机号码 4：修改手机号
-(void)getLoginCodeName:(NSString *)name toType:(LoginCodeStyle)type success:(successBlock)success
            failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:name,@"mobile",NSStringFromLoginCodeStyle(type),@"type", nil];
    [self POST:@"login/sendSms" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}
-(void)getRequestCodeButton:(UIButton *)sender mobile:(NSString *)mobile toType:(LoginCodeStyle)type{
    
    [[XWCommon shareAppDelegate].window endEditing:YES];
    if(mobile.length == 0||mobile.length != 11){
        [UIView xw_hideTitle:@"请填写正确的手机号码"];
        return;
    }
    
    [UIView xw_showHUDWithTitle:@"获取验证码中.."];
    [[TPRequestClient sharedClient]getLoginCodeName:mobile toType:type success:^(NSURLSessionDataTask *task, id responseObject, Responese *respone) {
         [UIView xw_hideHUD];
         [sender startTime:60 title:sender.titleLabel.text waitTittle:@"'s"];
       
        
    } failure:^(NSURLSessionDataTask *task, NSError *error, Responese *respone) {
        [UIView xw_hideTitle:respone.message];
        
    } nonetWork:^(NSURLSessionDataTask *task, NSError *error) {
        [UIView xw_hideTitle:error.localizedDescription];
    }];
}

//设置密码
-(void)getEditPsw:(NSString *)pass success:(successBlock)success
                failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:pass,@"confirm_password",pass,@"password",nil];
    [self POST:@"user/setPassword" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//修改密码
-(void)getUpdOldPsw:(NSString *)oldPsw toPass:(NSString *)psw  success:(successBlock)success
          failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:psw,@"new_password",psw,@"confirm_password",oldPsw,@"old_password",nil];
    [self POST:@"user/editPassword" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//修改设置手机 3：设置手机号码 4：修改手机号码
-(void)getEditPhone:(NSString *)phone code:(NSString *)code user_name:(NSString *)user_name  success:(successBlock)success
            failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:phone,@"mobile",code,@"code",xw_getNULLString(user_name),@"user_name",nil];
    [self POST:@"user/bindMobile" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//绑定微信接口
-(void)getSetWxchatCode:(NSString *)code success:(successBlock)success
          failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:code,@"code",nil];
    [self POST:@"tourist/setWxchat" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//解绑微信
-(void)getCancelWxchat_success:(successBlock)success
               failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self POST:@"tourist/cancelWxchat" parameters:@{} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


//编辑用户
-(void)getIntermediaryEditName:(NSString *)name emcard:(NSString *)emcard sex:(NSString *)sex photo:(NSString *)photo idcard:(NSString *)idcard success:(successBlock)success
              failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:xw_getNULLString(name),@"name",emcard,@"emcard", sex,@"sex",xw_getNULLString(photo),@"photo",idcard,@"idcard",nil];
    [self POST:@"tourist/touristEdit" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//获取个人信息
-(void)getInfo_success:(successBlock)success
                   failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self GET:@"user" parameters:@{} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//退出登录
-(void)getloginOut_success:(successBlock)success
                      failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self POST:@"tourist/loginOut" parameters:@{} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//获取七牛云
-(void)getUploadTokenSuccess:(successBlock)success
                   failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self POST:@"qnAccessToken" parameters:@{} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


//编辑个人信息
-(void)getupdInfoTouristEditKey:(NSString *)key value:(NSString *)value success:(successBlock)success
                failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:xw_getNULLString(value),@"value",key,@"column",nil];
    [self POST:@"user/editUserInfo" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
    
}

-(void)getupdInfoTouristEditDict:(NSDictionary *)dict success:(successBlock)success
                        failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    
    [self POST:@"tourist/touristEdit" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


//意见反馈
-(void)getFeedbackMessage:(NSString *)message success:(successBlock)success
                  failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:xw_getNULLString(message),@"msg",nil];
    [self POST:@"feedback/add" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//广告
-(void)getAdList_success:(successBlock)success
                          failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self GET:@"home/banner" parameters:@{} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//城市列表
-(void)getGetAllCity_success:(successBlock)success
                     failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
  [self GET:@"home/districts" parameters:@{} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


//1:关于我们 2：使用教程 3:引导流程
-(void)getIntroductionType:(NSInteger )type success:(successBlock)success
                   failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
 [self POST:@"phoneutil/getIntroduction" parameters:@{@"type":@(type)} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


//商品分类
-(void)getTemplateCategory_success:(successBlock)success
                 failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{

    [self GET:@"home/category" parameters:@{@"paginate":@100} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//商品效果
-(void)getTemplateEffect_success:(successBlock)success
                           failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self GET:@"home/effect" parameters:@{@"paginate":@100} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}

//诊所列表
-(void)getTemplateClinic_success:(successBlock)success
                         failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    [self GET:@"clinic/list" parameters:@{@"paginate":@100,@"city":@"广州"} progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


//模板列表
-(void)getTemplateListCateId:(NSInteger)categoryId cityName:(NSString *)cityName goods_salenum:(NSString *)goods_salenum clinic_id:(NSInteger)clinic_id name:(NSString *)name recommend:(BOOL)recommend current:(NSInteger )current size:(NSInteger )size success:(successBlock)success
                     failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:xw_getNULLString(cityName),@"city",@(current),@"page",@(size),@"paginate",nil];
    
    if(categoryId>0)
    [dict setObject:@(categoryId) forKey:@"category_id"];
    if(clinic_id>0)
        [dict setObject:@(clinic_id) forKey:@"clinic_id"];
    if(recommend)
        [dict setObject:@(recommend) forKey:@"recommend"];
    if(name.length>0)
        [dict setObject:name forKey:@"name"];
    
    
    [self GET:@"product/getProductList" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];

}

//商品详情
-(void)getTemplateInfotemplateId:(NSInteger )templateId success:(successBlock)success
                         failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(templateId),@"goods_id",@([LoginModel shareLoginModel].userId),@"userId",nil];
    [self GET:@"product/getDetail" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}
//预约
-(void)getSubmitAppointmentShopId:(NSInteger)goods_id appoint_time:(NSString *)appoint_time appoint_money:(NSString *)appoint_money payment_method:(NSString *)payment_method success:(successBlock)success
                          failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(goods_id),@"goods_id",xw_getNULLString(appoint_time),@"appoint_time",appoint_money,@"appoint_money",payment_method,@"payment_method",nil];
    [self POST:@"appointment" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}
//加入收藏
-(void)getCollectionCreateId:(NSInteger )templateId isAdd:(BOOL)isAdd success:(successBlock)success
                         failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(templateId),@"goodsId",isAdd ? @"add":@"delete",@"operating",nil];
    [self POST:@"personal/addOrDelCollection" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}




#pragma mark -----内容
//内容列表
-(void)getArticlePinglunList_current:(NSInteger )current size:(NSInteger )size success:(successBlock)success
                          failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(current),@"page",@(size),@"paginate",nil];
    [self GET:@"product/article" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
    
}
//内容详情
-(void)getArticleDetail_current:(NSInteger )current size:(NSInteger )size article_id:(NSInteger)article_id success:(successBlock)success
                             failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(current),@"page",@(size),@"paginate",@(article_id),@"article_id",nil];
    [self GET:@"product/article/detail" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
    
}
//发布内容
-(void)getArticleReplyId:(NSInteger )article_id content:(NSString *)content success:(successBlock)success
                     failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(article_id),@"article_id",content,@"content",nil];
    [self POST:@"article/reply" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
}


#pragma mark -----我的

//我的收藏
-(void)getUserCollection_current:(NSInteger )current size:(NSInteger )size success:(successBlock)success
                         failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(current),@"page",@(size),@"paginate",nil];
    
    [self GET:@"collection" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
    
}


//我的预约
-(void)getUserAppointment_current:(NSInteger )current size:(NSInteger )size success:(successBlock)success
                         failure:(failureBlock)failure nonetWork:(nonetWorkBlock)nonetWorkBlock{
    
     NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(current),@"page",@(size),@"paginate",nil];
    [self GET:@"appointment/List" parameters:dict progress:nil success:success failure:failure nonetWork:nonetWorkBlock];
    
}




@end
